<?php

// n_del.php
// Michael Baker
// 2010.07.12
//
// Delete a node (complain if it is not an orphan)

session_start();

define("IN_MDM", true);
define("CUR_PAGE_TITLE", "Delete node");
define("CUR_FLAG", "n.del");

/* Initialize database and ACL stuff here, so that the header.php can use it */
include '../includes/all.php';
include 'inc/header.php';

$id = $_GET[ "id" ];

if ( $_GET[ "confirm" ] )
{ 
  if ( count($dbase->search_for_nodecouples( $id )) )
  {
    // Can't delete node -- not orphan
    $_SESSION[ "MESSAGE" ] = array( 1, "Cannot delete node #$id: node is not an orphan" );
  }
  else 
  {
    // Node is orphan -- delete it
    $dbase->delete_node( $id );
    $_SESSION[ "MESSAGE" ] = array( 0, "Node #$id deleted" );
  }
  
  // redirect user to node list
  header( "Location: n_list.php" );
}
else
{
  $_SESSION[ "from" ]        = "n_list.php";
  $_SESSION[ "to" ]          = "n_del.php?id=$id&confirm=1";
  $_SESSION[ "confirm_msg" ] = "Are you sure you wish to delete this node?";
  
  // redirect user to confirmation page
  header( "Location: confirm.php" );
}

?>